package com.xlh.dao.courseTest.helper;

import cn.hutool.core.collection.CollectionUtil;
import com.xlh.dao.courseTest.ExperimentVideoStatisticsMapper;
import com.xlh.pojo.courseTest.ExperimentVideoStatistics;
import com.xlh.pojo.courseTest.example.ExperimentVideoStatisticsExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author cfz
 */
@Repository
public class ExperimentVideoStatisticsMapperHelper {

    @Autowired
    private ExperimentVideoStatisticsMapper experimentVideoStatisticsMapper;


    public List<ExperimentVideoStatistics> getByCondition(Long taskId, List<Integer> userIds){

        ExperimentVideoStatisticsExample example = new ExperimentVideoStatisticsExample();
        example.createCriteria().andTaskIdEqualTo(taskId.intValue()).andUserIdIn(userIds);
        List<ExperimentVideoStatistics> experimentVideoStatistics = experimentVideoStatisticsMapper.selectByExample(example);

        return experimentVideoStatistics;
    }

    public ExperimentVideoStatistics getByCondition(Long courseId, Long classId, Long chapterId, Integer userId){

        ExperimentVideoStatisticsExample example = new ExperimentVideoStatisticsExample();
        example.createCriteria().andCourseIdEqualTo(courseId.intValue()).andClassIdEqualTo(classId.intValue()).andChapterIdEqualTo(chapterId.intValue()).andUserIdEqualTo(userId);
        List<ExperimentVideoStatistics> experimentVideoStatistics = experimentVideoStatisticsMapper.selectByExample(example);

        if(CollectionUtil.isNotEmpty(experimentVideoStatistics)){
            return experimentVideoStatistics.get(0);
        }
        return null;
    }


}
